﻿using System;
using System.Reflection;
using System.Windows.Forms;
using Ast.Framework.Environment;
using Ast.Framework.Environment.AutofacUtil;
using Ast.Framework.Forms;

namespace Ast
{
    internal static class Program
    {
        private static IHost _host;

        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        [STAThread, LoaderOptimization(LoaderOptimization.MultiDomainHost)]
        public static void Main()
        {
            AutofacAssemblyStore.LoadAssembly("Ast.Framework");
            AutofacAssemblyStore.LoadAssembly("Ast.Core");
            AutofacAssemblyStore.LoadAssembly(Assembly.GetExecutingAssembly());

            _host = HostStarter.CreateHost();
            _host.Activate();

            var formFactory = ((IHostContainer) _host).Resolve<IFormFactory>();
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Application.Run(formFactory.Create(FormType.Main));

            _host.Terminate();
        }
    }
}